## traditional MM Likert outcome using white distractor photos
## only target photos used for analysis
##
## August 7, 2019
##
## Kevin Quinn
## University of Michigan
##

library(MCMCpack)
set.seed(522009)

mydata <- read.csv("../ScaleRaceSpring2017clean.csv")

## subset data
mydata <- mydata[mydata$condition %in% c("P1W", "P2W"),]


## keep target responses and photo IDs but nothing else
target.inds <- c(6, 7, 10, 12, 15, 17, 19, 20, 22, 23)
keep.vars <- c(paste("X", target.inds, "_Q339", sep=""),
               paste("X", target.inds, "a.id", sep=""))

mydata.sub <- mydata[, keep.vars]




## reshape into long format
mydata.sub.long <- reshape(mydata.sub, direction="long",
                           varying=list(c(1:10), c(11:20)),
                           v.names=c("Y", "photoID"),
                           ids=rownames(mydata.sub))

## keep only obs with non-missing values for MM
mydata.sub.long <- na.omit(mydata.sub.long)

mydata.sub.long <- mydata.sub.long[sample(1:nrow(mydata.sub.long),
                                          size=1000, replace=FALSE),]

cat("\n\nN =", nrow(mydata.sub.long), "\n\n") 


b4.M1.out <- MCMCoprobit(Y ~ as.factor(photoID), data=mydata.sub.long,
                         burnin=50000, mcmc=1000000, thin=50, tune=0.05,
                         verbose=10000, seed=904210
                         )


save(b4.M1.out, file="MM3.2.b4.M1.out.Rda")
